var wxRequest = require('../../utils/wxRequest')
var Common = require('../../utils/common');
const app = getApp();

Page({
  goto: app.goto,
  /**
   * 页面的初始数据
   */
  data: {
    mrRoom:null,
    billCountByRoom:{
      countNotPay:0,
      countOverdue:0
    }
  },

  

  goto_house_bind: function () {
    if (this.data.mrRoom == null) {
      wx.navigateTo({
        url: '../house_bind/house_bind'
      })
    }
  },

  goto_bill_rent_unpaid: function (e) {
    if (this.data.billCountByRoom.countNotPay == 0){
      app.toast('嗷~没有对应账单哦');
      return false;
    }

    console.log(e.currentTarget.dataset.url);
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },

  goto_bill_rent_overdue: function (e) {
    if (this.data.billCountByRoom.countOverdue == 0) {
      app.toast('嗷~没有对应账单哦');
      return false;
    }

    console.log(e.currentTarget.dataset.url);
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.init(this);

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _that = this;
    var url = app.globalData.domain + "/client/community/getMrRoom";
    var parm = {
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity")
    }
    wxRequest.postRequest(url, parm).then(res => {
      console.log("获取当前房屋", res.data);
      _that.setData({
        mrRoom: res.data
      });

      var getBillByCountUrl = app.globalData.domain + "/client/propertyBill/getBillCountByRoom";
      var parm = {
        token: wx.getStorageSync("token"),
        idRoom: res.data.idRoom
      }
      wxRequest.postRequest(getBillByCountUrl, parm).then(result => {
        console.log("获取指定房屋账单统计", result);
        _that.setData({
          billCountByRoom: result.data
        });

      }, error => {
        Common.showToast(error);
      });
    }, error => {
      Common.showToast(error);
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  notopen: function () {
    app.toast('海南城市暂未开放此功能，敬请期待~');
  },

  no_open: function () {
    app.toast('该小区暂无此收费项目');
  },
  no_open1: function () {
    app.toast('该小区未申请电子发票，请联系物业');
  },
  no_open2: function () {
    app.toast('该小区暂未开放此功能');
  },

})